<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Connecting: GNOME Data Access 5 manual</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="index.html" title="GNOME Data Access 5 manual">
<link rel="up" href="getting_started.html" title="Code examples">
<link rel="prev" href="getting_started.html" title="Code examples">
<link rel="next" href="ch06s03.html" title="Executing queries">
<meta name="generator" content="GTK-Doc V1.32 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="5"><tr valign="middle">
<td width="100%" align="left" class="shortcuts"></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
<td><a accesskey="u" href="getting_started.html"><img src="up.png" width="16" height="16" border="0" alt="Up"></a></td>
<td><a accesskey="p" href="getting_started.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
<td><a accesskey="n" href="ch06s03.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
</tr></table>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="connections"></a>Connecting</h2></div></div></div>
<p>
      <span class="application">Libgda</span> allows data sources (DSN) to be defined and referred to by a unique name which contains all the 
      required information to actually open a connection (except the name and password if they are required);
      see the <a class="link" href="libgda-5.0-Configuration.html" title="Configuration">Configuration section</a> for more information about
      how to manage data sources. Of
      course it's still possible to open a connection without having defined a DSN, in which case a <span class="emphasis"><em>connection
      string</em></span> is used to specify all the parameters required to open a connection. For more information
      about connection strings, see the <a class="link" href="GdaConnection.html#gda-connection-open-from-string" title="gda_connection_open_from_string ()">gda_connection_open_from_string ()</a>'s documentation.
    </p>
<p>
      Connections are opened using <a class="link" href="GdaConnection.html#gda-connection-open-from-dsn" title="gda_connection_open_from_dsn ()">gda_connection_open_from_dsn ()</a> for
      connections which are defined as a data source (DSN), or
      or <a class="link" href="GdaConnection.html#gda-connection-open-from-string" title="gda_connection_open_from_string ()">gda_connection_open_from_string ()</a> otherwise. 
      Each connection object can then be used to actually execute queries, for example:
      </p>
<pre class="programlisting">
void
do_stuff () {
	GdaConnection *connection;
      
        /* open a connection */
	g_print ("CONNECTING\n");
	connection = gda_connection_open_from_dsn ("calvaris", NULL, 
                                                   GDA_CONNECTION_OPTIONS_READ_ONLY, NULL);
	if (!connection) {
		g_print ("CONNECTION FAILED\n");
		return;
	}
	g_print ("CONNECTED\n");
      
        /* use the connection */
	execute_some_queries (connection);
      
        /* close the connection */
        g_object_unref (G_OBJECT (connection));
}
      </pre>
<p>
    </p>
<p>
      Closing the connection can be ordered using <a class="link" href="GdaConnection.html#gda-connection-close" title="gda_connection_close ()">gda_connection_close ()</a>,
      or is automatically done when the connection object is destroyed (as is the case in the example above when 
      <a href="/usr/share/gtk-doc/html/gobject/gobject-The-Base-Object-Type.html#g-object-unref">g_object_unref()</a> is called with the connection as argument).
    </p>
</div>
<div class="footer">
<hr>Generated by GTK-Doc V1.32</div>
</body>
</html>